#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
typedef struct QNode
{
	int x;
	int y;
	int val;
	struct QNode* next;
}QNode;
typedef struct Queue
{
	QNode* head;
	QNode* rear;
	int size;
}Queue;
void QueuePush(Queue* q, int x1, int y1, int val1)
{
	QNode *p= (QNode*)malloc(sizeof(QNode));
	p->val = val1;
	p->x = x1;
	p->y = y1;
	p->next = NULL;
	if (q->head == NULL)
		q->head = p;
	else
	{
		q->rear->next = p;
	}
	q->rear = p;
	q->size++;
}
void swap(QNode* j, QNode* q)
{
	int x1=j->x;
	int y1=j->y;
	int v=j->val;
	j->x=q->x;
	j->y=q->y;
	j->val=q->val;
	q->x = x1;
	q->y = y1;
	q->val = v;
}
void QueuePop(Queue* q)
{
	QNode* d = q->head;
	if (d == q->rear)
	{
		free(q->head);
		q->head = NULL;
		q->rear = NULL;
		return;
	}
	while (d->next != q->rear)
		d = d->next;
	free(q->rear);
	q->rear = d;
	d->next = NULL;
	q->size--;
}
void sort(Queue* q)
{
	int i = 0;
	QNode* head = q->head;
	for (i; i < q->size - 1; i++)
	{
		head = q->head;

		int j = 0;
		for (j; j < q->size - i - 1; j++)
		{
			if (head->x > head->next->x)
			{
				swap(head, head->next);
			}
			else if (head->x == head->next->x && head->y > head->next->y)
			{
				swap(head, head->next);

			}
			head = head->next;
		}
	}
}
int main()
{
	int a;
	int b;
	scanf("%d %d", &a, &b);
	//printf("%d %d\n", a, b);
	Queue q;
	q.head = NULL;
	q.rear = NULL;
	q.size = 0;
	while (a --)
	{
		int x, y, val;

		scanf("%d %d %d", &x, &y, &val);
		//printf("%d %d %d\n", x, y, val);

		QueuePush(&q, x, y, val);
	}
	while (b--)
	{
		int x, y, val;
		scanf("%d %d %d", &x, &y, &val);
		//printf("%d %d %d\n", x, y, val);

		QNode* phead = q.head;
		int flag = 1;
		while (phead)
		{
			if (phead->x == x)
			{
				if (phead->y == y)
				{
					phead->val += val;
					flag = 0;
					if (phead->val == 0)
					{
						swap(phead,q.rear);
						QueuePop(&q);
					}
					break;
				}
			}
			phead = phead->next;
		}
		if (flag)
			QueuePush(&q, x, y, val);
	}
	sort(&q);
	int f = 1;
	while (q.head)
	{
		printf("%d %d %d\n", q.head->x, q.head->y, q.head->val);
		q.head = q.head->next;
		f = 0;
	}
	if (f)
		printf("-1 -1 -1\n");
}